package com.system.employment.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.employment.dao.EmploymentRepository;
import com.system.employment.entity.Employment;

@Service
@Transactional
public class EmploymentService implements IEmploymentService{
	@Autowired
	private EmploymentRepository employmentRepository;
	

	public void saveOrUpdate(Employment employment) {
		employmentRepository.save(employment);
	}


	public void delete(Employment employment) {
		employmentRepository.delete(employment);
	}
	
	@Override
	public void delete(List<Long> ids) {
		List<Employment> employments =  (List<Employment>) employmentRepository.findAll(ids);
		if(employments!=null) {
			employmentRepository.delete(employments);
		}
	}

	@Transactional(readOnly = true)
	public Employment findOne(Long id) {
		return employmentRepository.findOne(id);
	}

	@Transactional(readOnly = true)
	public List<Employment> findAll() {
		return (List<Employment>)employmentRepository.findAll();
	}


	public Page<Employment> findAll(Specification<Employment> spec, Pageable pageable) {
		return employmentRepository.findAll(spec, pageable);
	}
	
}
